package com.pocketsweet.ui.uilib.adapter;

import java.util.List;
import java.util.concurrent.TimeUnit;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.pocketsweet.R;
import com.pocketsweet.model.MLConsumeRecord;
import com.pocketsweet.utils.ToolKits;

public class RechargeListAdapter extends BaseListAdapter<MLConsumeRecord> {
	private Context context;

	public RechargeListAdapter(Context ctx) {
		super(ctx);
		this.context = ctx;
	}

	public RechargeListAdapter(Context ctx, List<MLConsumeRecord> datas) {
		super(ctx, datas);
		this.context = ctx;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_recharge, parent,
					false);
			viewHolder = new ViewHolder(convertView);
			convertView.setTag(viewHolder);

		} else {
			viewHolder = (ViewHolder) convertView.getTag();

		}
		viewHolder.refreshView(datas.get(position), position);
		return convertView;
	}

	public class ViewHolder {
		TextView tvRechargeNum;
		TextView tvTime;
		public View parent;
		private MLConsumeRecord item;

		public ViewHolder(View parent) {
			this.parent = parent;
			initView(parent);
		}

		public void initView(View parent) {
			tvRechargeNum = (TextView) parent.findViewById(R.id.tvRechargeNum);
			tvTime = (TextView) parent.findViewById(R.id.tvTime);
		}

		public void refreshView(MLConsumeRecord item, int i) {
			this.item = item;
			tvRechargeNum.setText(item.getRemark());
			tvTime.setText(ToolKits.showTime(item.getCreatedAt()));
		}
	}
}
